﻿using System;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using NetMQ;
using NetMQ.Sockets;
using Nito.AsyncEx;
using Serilog;

namespace CenterServerDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            
             
            
            IHost host = Host.CreateDefaultBuilder(args)
                
                .ConfigureServices(services =>
                {
                    // services.Configure<OptionsPort>(x =>
                    // {
                    //     x.PubPort = 6666;
                    // });
                    
                    

                    var remoteServer = new RemoteServer("127.0.0.1", 1234);
                    remoteServer.TopicTypes.Add(new TopicType()
                    {
                        
                        Topic = "top1",
                        Next = true,
                        NextTopic = "reply_top1"
                    });
                    services.Configure<OptionsRemoteServer>(x =>
                    {
                        x.Server.Add(remoteServer);
                        
                    });


                    services.Configure<HostOptions>(x =>
                    {
                        x.ShutdownTimeout = new TimeSpan(0, 0, 60);
                    }); 
                    services.AddHostedService<MqService>();

                    services.AddDefaultSerializeProvider();
                    services.AddMqService();

                }).UseSerilog(((context, configuration) =>
                {
                    configuration.ReadFrom.Configuration(context.Configuration);
                    configuration.Enrich.FromLogContext();
                } ))
                .Build();
            
            AsyncContext.Run(()=>host.RunAsync());
        }
    }
}